$def with (page)

$var title: Publisher: $page.name

$ subject_list = [('subjects', 20), ('places', 20), ('people', 10), ('times', 10)]

<div id="scrollHere"></div>

<div id="contentHead">
    <h1>
        $page.name
        <span class="count" id="coversCount">
            <em>Publisher</em> - <strong><span>$ungettext("1 work", "%(count)d works", page.work_count, count=page.work_count)</span></strong>
            $if page.ebook_count > 0:
                / <span class="ebookcount"><span id="ebooks">$ungettext("1 ebook", "%(count)s ebooks", page.ebook_count, count=commify(page.ebook_count))</span></span>
            $else:
                / 0 ebooks
            <span class="clickdata"></span>
        </span>
    </h1>
</div>

<div class="contentBody">
  $:render_template("books/custom_carousel", books=page.works, key="subjects", load_more={"url": page.key + ".json", "limit": len(page.works)})

	<div class="head">
	    <h2>
	        $_("Publishing History")
                <span class="shift">$:_('This is a chart to show the when this publisher published books. Along the X axis is time, and on the y axis is the count of editions published. <a href="#subjectRelated">Click here to skip the chart</a>.')</span>
	        <span class="count hidden chartZoom">&nbsp;<a href="javascript:;" class="resetSelection small">$_("Reset chart")</a> $_("or continue zooming in.")</span>
	        <span class="count chartUnzoom">&nbsp;$_("This graph charts editions from this publisher over time. Click to view a single year, or drag across a range.")</span>
	    </h2>
	</div>

    <script type="text/json+graph" id="graph-json-chartPubHistory">$:json_encode(page.publishing_history)</script>
<script type="text/javascript">
<!--
// FIXME: Please move this text/javascript to webpack entry point after you've worked out what it's doing
function parse_hash() {
    try {
    	var hash = document.location.hash || "#";
    	var tokens = hash.substr(1).split("&");
    	var d = {};
    	for (var i in tokens) {
    		if (tokens[i]) {
    			var kv = tokens[i].split("=");
    			d[kv[0]] = kv[1];
    	    }
    	}
    	return d;
    }
    catch (error) {
        // Work-around for IE weirdness
        return {};
    }
}

function set_hash(data) {
	var d = parse_hash();

	for (var k in data) {
		if (data[k])
			d[k] = data[k];
		else
			delete d[k];
	}

	var tokens = [];
	for (var k in d) {
		tokens[tokens.length] = k + "=" + d[k];
	}

    var hash = "#" + tokens.join("&");
    var current_hash = document.location.hash || "#";

    if (hash == current_hash)
        return;
	document.location.hash = hash;
}

var _hash = parse_hash();
//-->
</script>

    <div class="chart">
        <div class="chartYaxis">$_("Editions Published")</div>
        <div id="chartPubHistory" class="thisChart">
            <noscript>$_("You need to have JavaScript turned on to see the nifty chart!")</noscript>
        </div>
        <div class="chartXaxis">$_("Year of Publication")</div>
    </div>

    <div class="clearfix"></div>

        <div class="head" id="subjectRelated">
            <h2>$_("Common Subjects")
                <span class="count">        <a href="/search?${page.subject_type}_facet=$page.name.replace('&','%26')">Search for books published by $page.name</a></span>
            </h2>
        </div>

	$jsdef renderSubjects(subjects):
	    $if len(subjects) > 0:
	        <span class="subject">
	        $for s in subjects:
	            <a href="$s.key">$s.name</a>$cond(loop.last, '', ',')
	        </span>
	    $else:
	        <span class="title"><em>$_("None found.")</em></span>

    $for s, limit in subject_list:
        <div class="contentQuarter link-box">
            <h6>$s</h6>
			<div class="subjects" id="subjects-$s">
				$:renderSubjects(page[s][:limit])
			</div>
        </div>
        $if s != 'times':
            <div class="contentSpacer"></div>

    <div class="clearfix"></div>

$jsdef renderAuthors(authors):
    $for a in page.authors:
        <span class="tag">
            <a href="$a.key" title="$_('See more books by, and learn about, this author')">$a.name</a>,
        </span>
        <span class="count">$ungettext("1 book", "%(count)d books", a.count, count=a.count)</span>
        <br/>
<div id="resultsAuthors" class="widget-box">
    <div class="head">
        <h3>$_("Authors")</h3>
        <div class="smallest lightgreen sansserif">$_("published most by this publisher")</div>
    </div>
    <div class="unordered">
        $:renderAuthors(page.authors)
    </div>
</div>
<div class="spacer"></div>

$ publishers_feature_enabled = "publishers" in ctx.features

<script type="text/javascript">
<!--
    $ page_key = page.key[page.key.rindex('/')+1:]
    var page_key = "$page_key";
    var publishers_feature_enabled = $:json_encode(publishers_feature_enabled);
//-->
</script>
$jsdef renderPublishers(publishers):
    $for p in publishers:
        <span class="tag">
            $if publishers_feature_enabled:
                <a href="$p.key">$p.name</a>,
            $else:
                <a href="/search?${page.subject_type}_facet=$page.name.replace('&','%26')&amp;publisher_facet=$p.name.replace('"', '\\"').replace('&','%26')" title="$_('Get more information about this publisher')">$p.name</a>,
        </span>
        <span class="count">$ungettext("1 edition", "%(count)s editions", p.count, count=commify(p.count))</span>
         <br/>

<div class="section clearfix"></div>

<form action="/search/publishers" class="olform">
    <h2 class="collapse"><label for="searchSubjects">Publisher Search</label>  <span class="sansserif grey smaller">Try a keyword.</span></h2>
    <p>
        <input type="text" name="q" id="searchSubjects" size="100" class="larger" value="" />
        <button type="submit" class="larger">$_('Search')</button>
    </p>
</form>

</div>
